package com.yay.mashiro.yayclient.ui.clickgui;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;

import com.yay.mashiro.yayclient.module.Category;
import com.yay.mashiro.yayclient.ui.clickgui.panel.WindowPanel;
import com.yay.mashiro.yayclient.ui.clickgui.panel.CategoryPanel;
import com.yay.mashiro.yayclient.ui.clickgui.panel.SideBar;

import net.minecraft.client.gui.GuiScreen;

public class ClickGUI extends GuiScreen {
	
	SideBar sideBar;
	private ArrayList<WindowPanel> windows = new ArrayList<>();
	
	
	public ClickGUI() {
		
		this.sideBar = new SideBar();
		this.windows.add(new WindowPanel(Category.Combat));
		this.windows.add(new WindowPanel(Category.Movement));
		this.windows.add(new WindowPanel(Category.Player));
		this.windows.add(new WindowPanel(Category.Render));
		this.windows.add(new WindowPanel(Category.World));
	}
	
	@Override
	public void drawScreen(int mouseX, int mouseY, float partialTicks) {
		
		Iterator<WindowPanel> iterator = null;
        CategoryPanel LeftPanel = null;
        try {
            this.sideBar.draw();
            Iterator<CategoryPanel> iterator2 = this.sideBar.button.iterator();
            do {
                if (!iterator2.hasNext()) return;
                LeftPanel = iterator2.next();
            } while (!LeftPanel.active.booleanValue());
            iterator = this.windows.iterator();
        }
        catch (Throwable throwable) {
            // empty catch block
//            return;
        }
        while (iterator.hasNext()) {
            WindowPanel CategoryPanel = iterator.next();
            if (!CategoryPanel.category.toString().equals(LeftPanel.title)) continue;
            CategoryPanel.draw(mouseX, mouseY);
            return;
        }
	}
	
	@Override
	protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException {
				
		Iterator<WindowPanel> iterator;
        CategoryPanel LeftPanel;
        try {
            this.sideBar.onMouseClick(mouseX, mouseY);
            Iterator<CategoryPanel> iterator2 = this.sideBar.button.iterator();
            do {
                if (!iterator2.hasNext()) return;
                LeftPanel = iterator2.next();
            } while (!LeftPanel.active.booleanValue());
            iterator = this.windows.iterator();
        }
        catch (Throwable throwable) {
            // empty catch block
            return;
        }
        while (iterator.hasNext()) {
            WindowPanel CategoryPanel = iterator.next();
            if (!CategoryPanel.category.toString().equals(LeftPanel.title)) continue;
            CategoryPanel.onMouseClick(mouseX, mouseY, mouseButton);
            return;
        }
	}
	
	@Override
	protected void mouseReleased(int mouseX, int mouseY, int state) {
		
		super.mouseReleased(mouseX, mouseY, state);
	}
}
